package com.beijing.cyou.config;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import redis.clients.jedis.JedisPoolConfig;

@Configuration
public class RedisPool implements InitializingBean {

	@Value("${jedis.pool.host}")
	private String host ;
	
	@Value("${jedis.pool.port}")
	private Integer port ;
	
	@Value("${jedis.pool.timeout}")
	private Integer timeout ;
	
	@Value("${jedis.pool.password}")
	private String password ;

//	jedis.pool.config 
	
	private JedisPoolConfig poolConfig ;
	
	@Value("${jedis.pool.config.maxTotal}")
	private Integer maxTotal ;
	
	@Value("${jedis.pool.config.maxIdle}")
	private Integer maxIdle ;
	
	@Value("${jedis.pool.config.maxWaitMillis}")
	private Integer maxWaitMills ;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		 poolConfig = new JedisPoolConfig();  
		 poolConfig.setMaxWaitMillis(maxWaitMills);  
		 poolConfig.setMaxTotal(maxTotal);  
		 poolConfig.setMaxIdle(maxIdle); 
	}
	public JedisPoolConfig getPoolConfig() {
		return poolConfig;
	}
	public void setPoolConfig(JedisPoolConfig poolConfig) {
		this.poolConfig = poolConfig;
	}
	
	public Integer getMaxTotal() {
		return maxTotal;
	}
	public void setMaxTotal(Integer maxTotal) {
		this.maxTotal = maxTotal;
	}
	
	public Integer getMaxIdle() {
		return maxIdle;
	}
	public void setMaxIdle(Integer maxIdle) {
		this.maxIdle = maxIdle;
	}
	
	public Integer getMaxWaitMills() {
		return maxWaitMills;
	}
	public void setMaxWaitMills(Integer maxWaitMills) {
		this.maxWaitMills = maxWaitMills;
	}
	
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}

	public Integer getPort() {
		return port;
	}
	public void setPort(Integer port) {
		this.port = port;
	}

	public Integer getTimeout() {
		return timeout;
	}
	public void setTimeout(Integer timeout) {
		this.timeout = timeout;
	}

	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	
}
